package com.cf.user.permission.model;

import com.cf.code.core.CField;
import com.cf.code.core.CModel;
import com.cf.code.core.CPage;
import com.cf.crud.entity.BaseEntity;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

@Entity
@Table(name = "systemPermission",
        uniqueConstraints = {
                @UniqueConstraint(columnNames = "permissionUrl")
        }
)

@CModel(pages = {
        @CPage(title = "权限列表", path = "systemPermission", templateName = "list.ftl", outPutName = "list.ftl"),
        @CPage(title = "权限", path = "systemPermission", templateName = "add.ftl", outPutName = "add.ftl"),
        @CPage(title = "权限", path = "systemPermission", templateName = "update.ftl", outPutName = "update.ftl")
})
public class SystemPermission extends BaseEntity {

    @CField(lab = "父ID")
    @Column(name = "parentId")
    private long parentId;

    @CField(lab = "权限名字", search = true)
    @Column(name = "permissionName")
    private String permissionName;

    @CField(lab = "权限码")
    @Column(name = "permissionCode")
    private String permissionCode;

    @CField(lab = "权限路劲")
    @Column(name = "permissionUrl")
    private String permissionUrl;

    @Column(name = "createTime")
    @Temporal(TemporalType.TIMESTAMP)
    @CField(lab = "创建时间", show = false)
    private Date createTime = new Date();

    public long getParentId() {
        return parentId;
    }

    public void setParentId(long parentId) {
        this.parentId = parentId;
    }

    public String getPermissionName() {
        return permissionName;
    }

    public void setPermissionName(String permissionName) {
        this.permissionName = permissionName;
    }

    public String getPermissionCode() {
        return permissionCode;
    }

    public void setPermissionCode(String permissionCode) {
        this.permissionCode = permissionCode;
    }

    public String getPermissionUrl() {
        return permissionUrl;
    }

    public void setPermissionUrl(String permissionUrl) {
        this.permissionUrl = permissionUrl;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof SystemPermission)) return false;
        if (!super.equals(o)) return false;
        SystemPermission that = (SystemPermission) o;
        return getParentId() == that.getParentId() &&
                Objects.equals(getPermissionName(), that.getPermissionName()) &&
                Objects.equals(getPermissionCode(), that.getPermissionCode()) &&
                Objects.equals(getPermissionUrl(), that.getPermissionUrl()) &&
                Objects.equals(getCreateTime(), that.getCreateTime());
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), getParentId(), getPermissionName(), getPermissionCode(), getPermissionUrl(), getCreateTime());
    }

}
